package com.smartmore.test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class Image1 extends Activity {
    /** Called when the activity is first created. */
	
	float mx, my;
	float curX, curY;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image1_layout);
        
       
        
        final ImageTestView1 imgView1 = (ImageTestView1) this.findViewById(R.id.img1);
        imgView1.setWillNotDraw(false);
        //final ImageView switcherView2 = (ImageView) this.findViewById(R.id.img2);
       
        
        
        /*
        switcherView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View arg0, MotionEvent event) {
                

                switch (event.getAction()) {

                    case MotionEvent.ACTION_DOWN:
                        mx = event.getX();
                        my = event.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        curX = event.getX();
                        curY = event.getY();
                        
                        
//                        int xDiff = (int) (mx - curX);
//                        int yDiff = (int) (my - curY);
                        
                       
                       
                        break;
                    case MotionEvent.ACTION_UP:
                        int xDiff = (int) (mx -curX);
                        int yDiff = (int) (my - curY);
                    	
                        Log.d("scroollTo",xDiff+","+ yDiff);
                       
                        switcherView.scrollBy(xDiff, yDiff);
                        
                        if(switcherView.getScrollX() < 0 ) {

                        	xDiff = 0;
                        	switcherView.scrollTo(0, switcherView.getScrollY());
                        }
                        
                        if(switcherView.getScrollY() < 0 ) {

                        	xDiff = 0;
                        	switcherView.scrollTo(switcherView.getScrollX(),0);
                        }
                        
                        
	                    
                        Log.d("scroollXY",switcherView.getScrollX()+","+ switcherView.getScrollY());
	                    
	                    
	                    //Log.d("scroollXY",":"+switcherView.getDrawingCache().getWidth()+","+ switcherView.getDrawingCache().getHeight());
	                    
	                    //switcherView.getDrawingRect(outRect);
	                    
	                    //Log.d("scroollXY=>",Log.d("scroollXY",switcherView.getScrollX()+","+ switcherView.getScrollY()); );
	                    
	                    
//	                    if(switcherView.getScrollX() < 0) {
//	                    	xDiff = 0;
//                        }
//	                    
//	                    if(switcherView.getScrollY() > 1028) {
//	                    	yDiff = 1028;                        	
//                        }
                        

	                    //switcherView.scrollTo(1024, 1024);
                        
                        
                       
  
                        mx = curX;
                        my = curY;
                        
//                        Rect outRect = new Rect();
//                        switcherView.getDrawingRect(outRect); 
//                        Log.d("rect","left=>"+outRect.left+","+outRect.top);
//                        
//                        
//                        //BitmapDrawable bitmapDrawable = (BitmapDrawable)getResources().getDrawable(R.id.img1);
//                        //Bitmap bitmap = bitmapDrawable.getBitmap();
//                        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.oldman);
//                        if(bitmap !=null) {
//                        	 Log.d("rect","bitmap=>"+bitmap.getWidth()+","+bitmap.getHeight());
//                        }else {
//                        	Log.d("rect","bitmap=> bitmap is null");
//                        }
//                        
//                        int left = (outRect.left < 0)?0:outRect.left;
//                        int top  = (outRect.right < 0)?0 : outRect.right;
//                        
//                        Bitmap createBitmap = Bitmap.createBitmap(bitmap, left, top, 300, 300);
//
//                        switcherView2.setImageBitmap(createBitmap);
                        
                        
                        break;
                }

                return true;
            }
        });
*/
        
//        switcherView2.setOnTouchListener(new View.OnTouchListener() {
//
//            public boolean onTouch(View arg0, MotionEvent event) {
//                switch (event.getAction()) {
//
//                    case MotionEvent.ACTION_DOWN:
//                        mx = event.getX();
//                        my = event.getY();
//                        break;
//                    case MotionEvent.ACTION_MOVE:
//                        curX = event.getX();
//                        curY = event.getY();
//                        
//                        
////                        int xDiff = (int) (mx - curX);
////                        int yDiff = (int) (my - curY);
//                        
//                       
//                       
//                        break;
//                    case MotionEvent.ACTION_UP:
//                        int xDiff = (int) (mx -curX);
//                        int yDiff = (int) (my - curY);
//                    	
//                        Log.d("scroollTo",xDiff+","+ yDiff);
//	                    switcherView2.scrollBy(xDiff, yDiff);
//	                    
//	                    
//	                    Log.d("scroollXY",switcherView2.getScrollX()+","+ switcherView2.getScrollY());
//	                    
//	                    //Log.d("scroollXY",":"+switcherView2.getDrawingCache().getWidth()+","+ switcherView2.getDrawingCache().getHeight());
//	                    
//	                    //switcherView.getDrawingRect(outRect);
//	                    
//	                    //Log.d("scroollXY=>",Log.d("scroollXY",switcherView.getScrollX()+","+ switcherView.getScrollY()); );
//	                    
//	                    /*
//	                    if(switcherView.getScrollX() < 0) {
//	                    	xDiff = 0;
//                        }
//	                    
//	                    if(switcherView.getScrollY() > 1028) {
//	                    	yDiff = 1028;                        	
//                        }
//                        */
//
//	                    //switcherView.scrollTo(1024, 1024);
//                        
//                        
//                       
//                    	/*
//                        curX = event.getX();
//                        curY = event.getY();
//                        //switcherView.scrollBy((int) (mx - curX), (int) (my - curY));
//                        
//                        Log.d("scroollXY",switcherView.getScrollX()+","+ switcherView.getScrollY());
//                        */
//                        mx = curX;
//                        my = curY;
//                        
//                        break;
//                }
//
//                return true;
//            }
//        });     
        
       
    }

}
